package com.codejoys.ssm.service.Impl;

import com.alibaba.druid.util.StringUtils;
import com.codejoys.ssm.dao.UserDao;
import com.codejoys.ssm.domain.Role;
import com.codejoys.ssm.domain.User;
import com.codejoys.ssm.domain.UserRole;
import com.codejoys.ssm.mapper.RoleMapper;
import com.codejoys.ssm.mapper.UserMapper;
import com.codejoys.ssm.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    private static final Logger logger=LoggerFactory.getLogger(UserServiceImpl.class);


    @Autowired
    UserDao userDao;

    @Autowired
    UserMapper userMapper;

    // 根据名字查询用户，同时查询角色信息
    @Override
    public List<User> findRolebyUser_Name(String name) {
        List<User> user=userDao.findRolebyUser_Name(name);
        return user;
    }


    //根据名字模糊查询用户，分页展示
    @Override
    public List<User> findByUser_Name(User user, Integer page, Integer limit) {
        if (!StringUtils.isEmpty(user.getName())){
            user.setName("%" + user.getName() + "%");
        }
        List<User> users = userDao.findByUser_Name(user,(page - 1) * limit, limit);
        return users;
    }

    @Override
    public void register(User user) {
        userMapper.insertSelective(user);
    }


}
